﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.Platform.Core.UI.Controls;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.ServiceModel;

namespace Baosight.ZNH.ZP.UI
{
    public partial class ZP12 : EFViewCmes
    {
        private EFTreeItem item;    //记录选中的树节点
        public ZP12()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ZP12_Loaded);
        }



        /// <summary>
        /// 加载树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ZP12_Loaded(object sender, RoutedEventArgs e)
        {
            this.tree.Refresh();
        }

        /// <summary>
        /// 设置初始化选中根节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tree_ItemPrepared(object sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e)
        {
            if (e.PreparedItem == null)
            {
                return;
            }
            EFTreeItem treeItem = e.PreparedItem as EFTreeItem;
            if (treeItem.Level == 0 && treeItem.Index == 0)
            {
                this.tree.SelectedItem = treeItem;//选中
                treeItem.ExpandItem();//展开
            }
        }

        /// <summary>
        /// 选择树节点右侧页面改变
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tree_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            Dictionary<string, string> args = new Dictionary<string, string>();
            string _value = "";
            if (this.tree.SelectedItems.Count > 0)
            {
                item = this.tree.SelectedItems[0] as EFTreeItem;
                _value = item.ItemObject.GetType().GetProperty("text").GetValue(item.ItemObject, null) as string;
                args.Add("orgCode", _value);
                _value = item.ItemObject.GetType().GetProperty("label").GetValue(item.ItemObject, null) as string;
                args.Add("orgName", _value);

                this.container.LoadView("ZP17", args);
            }
            if (args == null)
            {
                BaseTools.OpenEFWindowAlert("请选择机构！", null);
                return;
            }

        }

    }
}